﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//Author: ljj
//Date: 20190625
//Function: buff施加类,放在攻击上,与攻击一同结算
public class BuffAdderOnAttack
{
    public List<BuffInfo> buffList = new List<BuffInfo>();

    public void AddBuffToObj(GameObject obj)
    {
        if (buffList == null || buffList.Count <= 0) return;
        for (int i = 0; i < buffList.Count; i++)
        {
            BaseBuff buff = null;
            ConstOfBuff.BuffType buffType = (ConstOfBuff.BuffType)buffList[i].buffIndex;
            if (buffType == ConstOfBuff.BuffType.Slow)
            {
                buff = obj.GetComponent<Slow>();
                if (buff == null)
                    buff = obj.AddComponent<Slow>();
            }

            if (buffType == ConstOfBuff.BuffType.EarnMoney)
            {
                buff = obj.GetComponent<EarnMoney>();
                if (buff == null)
                    buff = obj.AddComponent<EarnMoney>();
            }

            if (buffType == ConstOfBuff.BuffType.LevelUp)
            {
                buff = obj.GetComponent<LevelUp>();
                if (buff == null)
                    buff = obj.AddComponent<LevelUp>();
            }

            if (buffType == ConstOfBuff.BuffType.Burn)
            {
                buff = obj.GetComponent<Burn>();
                if (buff == null)
                    buff = obj.AddComponent<Burn>();
            }

            if (buffType == ConstOfBuff.BuffType.CatchGoalSlow)
            {
                buff = obj.GetComponent<CatchGoalSlow>();
                if (buff == null)
                    buff = obj.AddComponent<CatchGoalSlow>();
            }

            if (buffType == ConstOfBuff.BuffType.RepeatableAttackIncrease)
            {
                buff = obj.GetComponent<RepeatableAttackIncrease>();
                if (buff == null)
                    buff = obj.AddComponent<RepeatableAttackIncrease>();
            }

            if (buffType == ConstOfBuff.BuffType.RepeatableMaxHpIncrease)
            {
                buff = obj.GetComponent<RepeatableMaxHpIncrease>();
                if (buff == null)
                    buff = obj.AddComponent<RepeatableMaxHpIncrease>();
            }

            if (buff != null)
                buff.Cover(buffList[i].effect, buffList[i].duration);
        }
    }
}

